/* tstream.hh
* This file is part of ncursesxx library
* Copyright (c) 2003,2004 by Stanislav Ievlev
*
* This file is covered by the GNU Library General Public License,
* which should be included with libncursesxx as the file COPYING.
*/
#ifndef NCURSESXX_TSTREAM_HH__
#define NCURSESXX_TSTREAM_HH__

#include <iostream>
#include <ncurses/terminal.hh>

namespace ncurses
{
	/**
	 * output terminal stream
	 * if fd is not real terminal, all extended features will be off
	 * @todo made as a template when a terminfo API will be ready
	 */
	class otstream: public std::basic_ostream<char>
	{
		typedef std::basic_ostream<char>	ostream_type;
	public:
		otstream(int fd):
				ostream_type(0),
				fdbuf_(fd, std::ios_base::out, false, BUFSIZ),
				term_(fdbuf_)
		{
			this->init(&fdbuf_);
		}
		void reset_colors() { term_.reset_colors(); }
		void set_attr(chtype mode = A_NORMAL) { term_.set_attr(mode); }
		void set_fg_color(short color = COLOR_WHITE) { term_.set_fg_color(color); }
		void set_fg(short color, chtype mode = A_NORMAL) { term_.set_fg(color, mode); }
		color_t	color() const { return term_.color(); }
		attr_t	attr() const { return term_.attr(); }
		int colors_num() const { return term_.colors_num(); }
	private:
		ext::sysio_filebuf<char>	fdbuf_; /**< internal output buffer*/
		terminal	term_; /**< internal terminal control object */
	};
}

#endif
